package br.com.locanet.service.impl;

import javax.persistence.PersistenceException;

import br.com.locanet.bean.impl.Funcionario;
import br.com.locanet.dao.database.impl.FuncionarioDAO;
import br.com.locanet.exception.ExceptionList;

public class FuncionarioService extends AbstractPessoaService<Funcionario, FuncionarioDAO>{
	
	@Override
	public void doValidateRequiredFields(Funcionario entity) throws ExceptionList{
		ExceptionList fieldsInvalidos = new ExceptionList();
		
		try{
			super.doValidateRequiredFields(entity);
		}catch(ExceptionList e){
				fieldsInvalidos.getListaErros().addAll(e.getListaErros());
		}
		
		if (!fieldsInvalidos.getListaErros().isEmpty()) throw fieldsInvalidos;
	}

	@Override
	public void doValidateBusinessRules(Funcionario entity) throws ExceptionList, PersistenceException, ClassNotFoundException{
		ExceptionList exceptionList = new ExceptionList();
		
		try{
			super.doValidateBusinessRules(entity);
		}catch(ExceptionList e){
			for (Exception ex : e.getListaErros())
				exceptionList.add(ex);
		}
		
		Funcionario func = new Funcionario();
		func.setId(entity.getId());
		func.setLogin(entity.getLogin());
		
		validaRepeticaoLogin(func, exceptionList);
		
		if (!exceptionList.getListaErros().isEmpty()) throw exceptionList;
	}
}
